import com.powerfl.frm.taf.*;

include "param/child.as";
include "param/bind.as";
include "param/text.as";
include "param/tween.as";

final internal function $paramGet( $param:Array ):TAFparam{
	var vars:*, param:TAFparam, p:*, key:*, child:int, tween:int;
	if( $param.length ){
		param = poolPullParam();
		for each( p in $param ){
			if( p is String ){
				switch( p ){
				case'@@TAFawayVar':
					if( SELF._paramAwayVar ){
						child = -1;
					}
					break;
				case'@@TAFtweenVar':
					if( SELF._paramTweenVar ){
						tween = -1;
					}
					break;
				default: param.addTag( p );
				}
			}else if( p is Array ){
				param.addBind( p );
			}else if( typeofObject( p ) ){
				param.addParam( p );
			}else if( p ){
				param.addVar( p );
			}
		}
		if( param.vars ){}else{
			if( tween < 0 ){
				if( child < 0 ){
					SELF._paramTweenCurrVar.to = SELF._paramAwayVar;
				}else if( param.param ){
					SELF._paramTweenCurrVar.to = param.param;
					param.param = null;
				}
				param.addVar( SELF._paramTweenVar );
				SELF._paramTweenVar = null;
				SELF._paramTweenCurrVar = null;
			}else if( child < 0 ){
				param.addVar( SELF._paramAwayVar );
			}
		}
		SELF._paramAwayVar = null;
		return param;
	}else{
		return null;
	}
}

private function $paramValueMake( $key:String, $value:* ):Object{
	var result:Object;
	result = {};
	result[$key] = $value;
	return result;
}
final public function $break( ...$param ):*{
	var result:*;
	if( SELF._paramTweenVar ){
		$NEXT.apply( null, $param );
		result = SELF._paramTweenVar;
		SELF._paramTweenVar = null;
	}else{
		result = SELF._paramAwayVar;
		SELF._paramAwayVar = null;
	}
	return result;
}
//-----------------------------------------------------------------------------------------------------------------------------------------
final public function $modeFlow():void{
	_initArg = '@@TAF_FLOW';
};
final public function $modeApp( ...$param ):void{
	if( _initArg is Array ){
		_initArg = _initArg.concat( $param );
	}else{
		_initArg = $param;
	}
};
final public function $modeAir( $title:String, $width:Number, $height:Number, $x:Number = -2147483648, $y:Number = -2147483648 ):void{
	var result:Array;
	result = [$title, $width, $height, $x, $y];
	if( _initArg is Array ){
		_initArg[_initArg.length] = result;
	}else{
		_initArg = [result];
	}
};
//-----------------------------------------------------------------------------------------------------------------------------------------
final public function $PROGRESS( $flowKey:String ):Object{
	return $paramValueMake( 'progress', flowGet( $flowKey ) );
}
final public function $POST( $val:Object, $encoding:String = 'utf-8' ):Object{
	return {post:$val,postEncoding:$encoding};
}
final public function $GET( $val:Object, $encoding:String = 'utf-8' ):Object{
	return {get:$val,gettEncoding:$encoding};
}
final public function $ADsystem():Object{
	return $paramValueMake( 'ad', ApplicationDomain.currentDomain );
}
final public function $ADinherite():Object{
	return $paramValueMake( 'ad', new ApplicationDomain( ApplicationDomain.currentDomain ) );
}
//-----------------------------------------------------------------------------------------------------------------------------------------
//public function $imageText( $text:String, $treeKey:String, $map:* ):Object{
//	var result:Object;
//	result = {text:$text, key:$treeKey};
//	if( $map is Array ){
//		result.map = $map; 
//	}else if( $map is String ){
//		result.map = tdata( $map );
//	}else{
//		error( 'map항목은 treeKey이거나 Array이어야합니다.' );
//	}
//	return result;
//}
//-----------------------------------------------------------------------------------------------------------------------------------------
//final public function $filterDisassem( $viewKey:String, $size:Array = null, $blend:String = 'ALPHA' ):Object{
//	return {type:'disassem', key:$viewKey, blend:$blend, size:$size};
//}
//
//final public function $filterDisassemADD( $bitmapKey:String, $x:int, $y:int, $width:int, $height:int, $time:Number, $elementTime:Number, $elementSpeed:Number, $dirX:int, $dirY:int, $size:Number, $startColor:uint, $startAlpha:Number, $endColor:uint, $endAlpha:Number, $blend:String  ):Object{
//	return {bitmap:$bitmapKey, x:$x, y:$y, width:$width, height:$height, time:$time, elementTime:$elementTime, elementSpeed:$elementSpeed, 
//		dirX:$dirX, dirY:$dirY, size:$size, startColor:$startColor, startAlpha:$startAlpha, endColor:$endColor, endAlpha:$endAlpha, blend:$blend};
//}
//final public function $filterFire( $viewKey:String ):Object{
//	return {type:'fire', key:$viewKey};
//}
//final public function $filterFireADD( $width:int, $height:int, $velocity:Number, $count:int, $term:Number, $gravity:Number = 0.045 ):Object{ //0.015
//	return {width:$width, height:$height, velocity:$velocity, count:$count, term:$term, gravity:$gravity};
//}
//final public function $filterFrameAni( $viewKey:String, $size:Array = null, $blend:String = 'ALPHA' ):Object{
//	return {type:'frameAni', key:$viewKey, blend:$blend, size:$size};
//}
//final public function $filterFrameAniADD( $tileKey:String, $lastIndex:int, $rate:int, $x:Number, $y:Number, $width:Number, $height:Number, $loop:int = 1, $blend:String = null  ):Object{ //0.015
//	return {tileKey:$tileKey, lastIndex:$lastIndex, rate:$rate, x:$x, y:$y, width:$width, height:$height, loop:$loop, blend:$blend};
//}
//final public function $filterRipple( $viewKey:String, $size:Array = null, $detail1_:uint = 8, $fluid1_100:uint = 100, $speed0_128:uint = 0  ):Object{
//	return {type:'ripple', key:$viewKey, detail:$detail1_, fluid:$fluid1_100, speed:$speed0_128, size:$size};
//}
//final public function $filterRippleADD2( $size:Number, $x:Number, $y:Number ):Object{
//	return {x:$x, y:$y, size:$size};
//}
//final public function $filterRippleADD( $size:*, $view:String, $tree:String ):Object{
//	var temp:*;
//	temp = getScreenPos( $view, $tree ); 
//	return {x:temp[0], y:temp[1], size:$size};
//}